<?php

/**
 * ============================================================================
 * 版权所有 多多科技，保留所有权利。
 * 网站地址: http://soft.duoduo123.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/

if (!defined('INDEX')) {
	exit ('Access Denied');
}
function act_m_dingdan2() {
	global $duoduo;
	$webset = $duoduo->webset;
	$dduser = $duoduo->dduser;
	$errorData = $duoduo->errorData;
	$do = empty ($_GET['do']) ? 'tao' : $_GET['do'];

	if ($do == 'tao') {
		$id = $_GET["id"] ? intval($_GET["id"]) : intval($_POST["id"]); //订单ID
		$trade = $duoduo->select('tradelist', '*', 'id="' . $id . '"');
		if($trade['trade_id_former']==0){
			$trade['trade_id_former']=preg_replace('/_\d+$/','',$trade['trade_id']);
			$data=array('trade_id_former'=>$trade['trade_id_former']);
			$duoduo->update('tradelist',$data,'id="' . $id . '"');
		}
		
		if (!$trade['id']) {
			jump(-1, $errorData[46]);
		}
		
		if ($trade['checked'] != 0) {
			jump(-1, $errorData[45]);
		}
		
		if ($_POST['sub'] == '') {

			if(TAOTYPE==2){
				$trade['trade_id_former']=$trade['trade_id'];
			}
			
			$trade['trade_id'] = fuzzyTradeId($trade['trade_id_former']);
		} else {
			$captcha = $_POST['captcha'];
			if (reg_captcha($captcha) == 0) {
				jump(-1, $errorData[5]);
			}
			$trade_id = trim($_POST['trade_id']);
			if(!preg_match('/^\d+$/',$trade_id)){
				$trade_id=0;
			}
			
			if (TAOTYPE == 2) { //淘宝api形式
				if ($trade['trade_id'] != $trade_id && $trade['mini_trade_id']!=substr($trade_id,0,8).substr($trade_id,-4)) {
					jump(-1, $errorData[47]);
				}
				if ($webset['taoapi']['trade_check'] == 1) { //人工审核
					$uploadname = 'up_pic';
					$file_name = upload($uploadname);
					if (is_numeric($file_name)) {
						jump(-1, $errorData[$file_name]);
					}

					$checked = 1;
					$data = array (
						'checked' => 1,
						'ddjt' => $file_name,
						'qrsj' => TIME,
						'outer_code' => $dduser['id'],
						'uid' => $dduser['id']
					);

					$duoduo->update('tradelist', $data, 'id="' . $id . '"');
					jump(p('m', 'tradelist'), '确认成功，等待网站审核');
				}
				elseif ($webset['taoapi']['trade_check'] == 0) { //自动审核
					$trade['ddjt'] = '';
					$trade['checked'] = 2;
					$duoduo->rebate($dduser, $trade, 8); //8号明细，确认淘宝订单
					jump(wap_l(MOD, 'dingdan'), '确认成功');
				}
			}
			elseif (TAOTYPE == 1) { //淘点金形式
				if($trade_id!=$trade['trade_id_former']){
					jump(-1, $errorData[46]);
				}
				if ($webset['taoapi']['trade_check'] == 1) { //人工审核
					$uploadname = 'up_pic';
					$file_name = upload($uploadname);
					if (is_numeric($file_name)) {
						jump(-1, $errorData[$file_name]);
					}
					$checked = 1;
					$data = array (
						'checked' => 1,
						'ddjt' => $file_name,
						'qrsj' => TIME,
						'outer_code' => $dduser['id'],
						'uid' => $dduser['id']
					);
					$where = 'trade_id_former = "' . $trade_id . '"';
					$duoduo->update('tradelist', $data, $where);
					jump(wap_l(MOD, 'dingdan'), '确认成功，等待网站审核');
				}
				elseif ($webset['taoapi']['trade_check'] == 0) { //自动审核
					$where = 'trade_id_former = "' . $trade_id . '" and uid=0 and checked=0';
					$trades = $duoduo->select_all('tradelist', '*',$where);
					foreach ($trades as $trade) {
						if ($trade['status'] == 5) {
							$trade['ddjt'] = '';
							$trade['checked'] = 2;
							$duoduo->rebate($dduser, $trade, 8); //8号明细，确认淘宝订单
						} else {
							$update['checked'] = 3;
							$update['outer_code'] = $dduser['id'];
							$update['uid'] = $dduser['id'];
							$duoduo->update('tradelist', $update, 'id=' . $trade['id']);
						}
					}
					
					if($webset['taoapi']['auto_fanli']==1){
						$duoduo->trade_uid($dduser['id'],$trade['trade_id_former'],'add');
					}
					
					jump(wap_l(MOD, 'dingdan'), '确认成功');
				}
			}
		}
	}
	elseif ($do == 'paipai') {
		if ($_POST['sub'] == '') {
			$id = $_GET["id"] ? intval($_GET["id"]) : 0; //订单ID
			$trade = $duoduo->select('paipai_order', '*', 'id="' . $id . '"');
			if (!$trade['id']) {
				jump(-1, $errorData[46]);
			}
			$trade['dealId'] = fuzzyTradeId($trade['dealId']);
		} else {
			dd_session_start();
			$captcha = $_POST['captcha'];
			if ($captcha != $_SESSION["captcha"]) {
				jump(-1, $errorData[5]);
			}
			$dealId = trim($_POST['dealId']);
			$id = $_POST["id"] ? intval($_POST["id"]) : 0; //订单ID
			$trade = $duoduo->select('paipai_order', '*', 'id="' . $id . '"');
			if ($trade['uid'] > 0) {
				jump(-1, $errorData[45]);
			}
			if ($trade['dealId'] != $dealId) {
				jump(-1, $errorData[47]);
			}
			$duoduo->rebate($dduser, $trade, 18); //18号明细，确拍拍认订单
			jump(p('m', 'tradelist', array (
				'do' => 'paipai'
			)), '确认成功');
		}
	}
	elseif ($do == 'mall') {
		if ($_POST['sub'] == '') {
			$id = $_GET["id"] ? intval($_GET["id"]) : 0; //订单ID
			$trade = $duoduo->select('mall_order', '*', 'id="' . $id . '"');
			if (!$trade['id']) {
				jump(-1, $errorData[46]);
			}
			$trade['order_code'] = fuzzyTradeId($trade['order_code']);
		} else {
			dd_session_start();
			$captcha = $_POST['captcha'];
			if ($captcha != $_SESSION["captcha"]) {
				jump(-1, $errorData[5]);
			}
			$order_code = trim($_POST['order_code']);
			$id = $_POST["id"] ? intval($_POST["id"]) : 0; //订单ID
			$trade = $duoduo->select('mall_order', '*', 'id="' . $id . '"');
			if ($trade['uid'] > 0) {
				jump(-1, $errorData[45]);
			}
			if ($trade['order_code'] != $order_code) {
				jump(-1, $errorData[47]);
			}
			if ($trade['status'] == 1) {
				$duoduo->rebate($dduser, $trade, 12); //12号明细，确认商城订单
			} else {
				$data = array (
					'uid' => $dduser['id']
				);
				$duoduo->update('mall_order', $data, 'id="' . $id . '"');
			}
			jump(p('m', 'tradelist', array (
				'do' => 'mall'
			)), '确认成功');
		}
	}
	unset ($duoduo);
	$parameter['do'] = $do;
	$parameter['trade'] = $trade;
	$parameter['id'] = $id;
	$parameter['errorData'] = $errorData;
	return $parameter;
}
?>
<?php
$parameter=act_m_dingdan2();
extract($parameter);
if($dduser['id']==0 || empty($dduser['id'])){
	jump(wap_l(MOD,'login'),'请先登录');
}
$webtitle=$webset['title'].'订单认领-找回订单';
include(TPLPATH.'/inc/header_3.tpl.php');
?>
<style type="text/css">
table,table td,table th{ border-collapse:collapse;background:#FFFFFF; text-align:center; height:40px;line-height:40px; font-size:14px; text-align:left; 
}
</style> 
   <div class="admin_xfl">
                    <ul>
            <li><a href="<?=wap_l('user','order',array('do'=>'taobao'))?>" <?php if($do=='taobao'){?>class="on"<?php }?>>淘宝订单</a> </li>
            <li><a href="<?=wap_l('user','order',array('do'=>'mall'))?>"<?php if($do=='mall'){?>class="on"<?php }?>>商城订单</a> </li>
            <li><a href="<?=wap_l('user','dingdan')?>"class="on">找回订单</a> </li>
                    </ul>
              	</div>
 <div class="wap-index">   
  <div class="p15"> 
      <form id="form2" name="form2" method="post" action="" onsubmit="return checkForm($(this))"  enctype="multipart/form-data">
       <div style="border:1px solid #FFCC7F; background-color:#FFFFE5; padding:8px; text-align:left">
            <?php if(TAOTYPE==1){?>
            注：未结算的订单不显示具体返利详情，请输入订单号进行确认，只要您输入的订单号与系统内的一致，这笔交易您就确认成功了。
            <?php }elseif(TAOTYPE==2){?>
			注：如果您发现系统没有自动返利给您，可能是您购买商品的时候未登录，请输入订单号进行确认，只要您输入的订单号与系统内的一致，这笔交易您就确认成功了。
			<?php }?>
        </div>
        <?php if($do=='tao'){?>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="130" height="35" align="right" style="border:1px solid #eee;">&nbsp;&nbsp;商品名称：</td>
            <td width="70%" height="35" align="left" style="border:1px solid #eee;">&nbsp;<font color="#dd0000"><?php echo $trade['item_title'];?></font><input type="hidden" name="id" value="<?php echo $id;?>" /></td>
          </tr>
		  <tr>
                          <td style="border:1px solid #eee;" height="35" align="right">&nbsp;&nbsp;淘宝订单号：</td>
                          <td style="border:1px solid #eee;" height="35" align="left">&nbsp;<font color="#dd0000"><?php echo $trade['trade_id'];?></font></td>
                        </tr>
                        <tr>
                          <td style="border:1px solid #eee;" height="35" align="right">&nbsp;&nbsp;单价：</td>
                          <td style="border:1px solid #eee;" height="35" align="left">&nbsp;<font color="#dd0000"><?php echo $trade['pay_price'];?> ( 成交数量：<?php echo $trade['item_num'];?> )</font></td>
                          </tr>
                          <?php if($trade['jifenbao']>0){?>
                        <tr>
                          <td style="border:1px solid #eee;" height="35" align="right">&nbsp;&nbsp;返<?=TBMONEY?>：</td>
                          <td style="border:1px solid #eee;" height="35" align="left">&nbsp;<font color="#dd0000"><?=jfb_data_type($trade['jifenbao'])?> 个 </font></td>
                          </tr>
                        <?php }?>
						   <?php if($webset['taoapi']['trade_check']==1){?>  <tr>
                          <td height="35" colspan="2" align="right" style="border:1px solid #eee;">&nbsp;
&nbsp;&nbsp;淘宝订单编号裁图：
                        <div id="newPreview" style=" width:300px; height:79px; margin-left:6px; margin-bottom:10px; background:url(images/ddjt.jpg); border:#CCC 1px solid"></div>
                          <p><em style="font-style:normal;margin-left:6px; margin-bottom:10px;" id="ckup_pic"></em><input id="up_pic" name="up_pic" class="required" word='订单截图必须上传' type="file" style="width:236px" />
                          </p>
                                              </font></td>
                          </tr>   <?php }?>   
						   <tr>
                            <td style="border:1px solid #eee;" height="35" align="right" id="ckjyh">&nbsp;&nbsp;淘宝订单号：</td>
                          <td style="border:1px solid #eee;" height="35" align="left">
                          <input name="trade_id" type="text" id="trade_id" class="ddinput required" num='y' style="width:100px;height:25px"/></td>
                          </tr>
                        <tr>
                          <td style="border:1px solid #eee;" height="35" align="right" id="ckyzm">&nbsp;&nbsp;验证码：</td>
                          <td style="border:1px solid #eee;" height="35" align="left"><input name="captcha" type="text" size="10" maxlength="4" class="ddinput required" style="width:60px; height:25px" />
                          &nbsp; <?=yzm()?></td>
                          </tr>
                        <tr>
                          <td height="55" colspan="3" align="left"><input style="margin-top:15px; margin-bottom:15px" type="submit" name="sub" value="找回订单"  class="register_dl"/></td>
                        </tr>
          </table>
          <?php }?>
   </form>
	  </div>
</div>
<?php
include(TPLPATH.'/inc/footer.tpl.php');
?>